// 1.引入公用样式表
require("../../assets/css/index.less");
// require("../../assets/fonts/iconfont.css")

// 2.引入当前样式表
require("./training.less");

// 引入插件

// 3.引入公用js模块
let validator = require("../../utils/validator.js");
let https = require("../../utils/https.js");
let local = require('../../utils/local.js');

// 4.引入工具函数
let dom = require("../../utils/dom.js");
// 判断是否有登录
dom.isToken();
dom.ready(function () {
	// 渲染底部Tab
	dom.render(1);
	// 跳转添加动态
	dom.goTo("#run", "sports");
	dom.goTo("#cycle", "cycling");
	dom.goTo("#train", "training");

	function renderList() {
		https.get('/api/train/courseList', function (res) {
			//判定
			if (res.errno == 0) {
				res.data.map(v => {
					console.log(v);
					if (v.courseId == 1) {//最新课程
						// console.log('最新', v);
						dom.$('#newCourseList').innerHTML += `
						<li>
                            <a href="courseIntro.html?id=${v.courseId}">
                                <img src="${https.BASE_URL + v.imgurl}" alt="">
                                <div class="p5">
                                    <h2 class="f16 m_b20">${v.name}</h2>
                                    <p class="f12">${v.desc}</p>
                                </div>
                            </a>
                        </li>`
					} else {//课程
						// console.log('课程', v);
						dom.$('#courseList').innerHTML += `
                        <li data-id="${v.courseId}">
                            <a href="courseIntro.html?id=${v.courseId}">
                                <img src="${https.BASE_URL + v.imgurl}" alt="">
                                <div class="p5">
                                    <h2 class="f16 m_b20">${v.name}</h2>
                                    <p class="f12">${v.desc}</p>
                                </div>
                            </a>
                        </li>`
					}
				})
			}
		})
	}
	renderList()

});
